package cn.stylefeng.guns.modular.timetest.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.Timetest;
import cn.stylefeng.guns.modular.timetest.service.ITimetestService;

/**
 * 时间测试控制器
 *
 * @author fengshuonan
 * @Date 2018-12-12 20:13:17
 */
@Controller
@RequestMapping("/timetest")
public class TimetestController extends BaseController {

    private String PREFIX = "/timetest/timetest/";

    @Autowired
    private ITimetestService timetestService;

    /**
     * 跳转到时间测试首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "timetest.html";
    }

    /**
     * 跳转到添加时间测试
     */
    @RequestMapping("/timetest_add")
    public String timetestAdd() {
        return PREFIX + "timetest_add.html";
    }

    /**
     * 跳转到修改时间测试
     */
    @RequestMapping("/timetest_update/{timetestId}")
    public String timetestUpdate(@PathVariable Integer timetestId, Model model) {
        Timetest timetest = timetestService.selectById(timetestId);
        model.addAttribute("item",timetest);
        LogObjectHolder.me().set(timetest);
        return PREFIX + "timetest_edit.html";
    }

    /**
     * 获取时间测试列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return timetestService.selectList(null);
    }

    /**
     * 新增时间测试
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Timetest timetest) {
        timetestService.insert(timetest);
        return SUCCESS_TIP;
    }

    /**
     * 删除时间测试
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer timetestId) {
        timetestService.deleteById(timetestId);
        return SUCCESS_TIP;
    }

    /**
     * 修改时间测试
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Timetest timetest) {
        timetestService.updateById(timetest);
        return SUCCESS_TIP;
    }

    /**
     * 时间测试详情
     */
    @RequestMapping(value = "/detail/{timetestId}")
    @ResponseBody
    public Object detail(@PathVariable("timetestId") Integer timetestId) {
        return timetestService.selectById(timetestId);
    }
}
